import { Controller, Get, Param, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { NoticeService } from './notice.service';
import { CurrentUser } from 'src/user/user.decorator';
import { UserSys } from 'src/user/userSys.entity';

@Controller('api/notice')
@ApiTags("通知管理")
@UseGuards(AuthGuard("jwt"))
export class NoticeController {
    constructor(
        private readonly noticeService: NoticeService
    ) { }

    @Get("getmine")
    @ApiOperation({ summary: "获取我的消息" })
    async getmine(
        @CurrentUser() user: UserSys
    ) {
        return await this.noticeService.getmine(user);
    }

    @Get(`:id/read`)
    @ApiOperation({ summary: "已读" })
    read(
        @Param("id") id: number
    ) {
        return this.noticeService.notice.update({
            id
        }, {
            read: true
        })
    }
}
